import { createStore } from "vuex";
import { getMusicLyric } from "@/request/api/item"

export default createStore({
    state: {
        playList: [{ 
            al: {
                id: 139617589,
                name: "Good night",
                pic: 109951166993032770,
                picUrl: "http://p4.music.126.net/SZdkJJCJoUioI6nbeLvuFA==/109951166993032762.jpg",
                pic_str: "109951166993032762",
            },
            id: 1805395376,
        }],
        playListIndex: 0,    //数组下标
        isbtnShow: true,     //暂停按钮的显示
        currentTime: 0,       //歌曲播放当前时间
        duration: 0,         //歌曲时间总长
        lyric: '',           //歌词
        ShowDetail: false,   //显示歌词详情
    },
    mutations: {
        // 是否显示播放与暂停按键
        updataIsbtnShow(state, value) {
            state.isbtnShow = value
        },
        // 播放歌曲当前进度时间
        updateCurrentTime(state, value) {
            state.currentTime = value
            // console.log(state.currentTime)
        },
        // 存储歌曲总时长
        updataDuration(state, value) {
            console.log(value)
            state.duration = value
        },
        // 获取歌单的所有歌曲数据
        updataPlaylist(state, value) {
            state.playList = value
        },
        // 更新playList数组的下标
        updataPlayListIndex(state, value) {
            state.playListIndex = value
        },
        // 获取歌词
        updataLyricList(state, value) {
            state.lyric = value
        },
        // 弹出歌词详情框
        updataIsShowDetail(state, value) {
            state.ShowDetail = !state.ShowDetail
        },
        pushPlayList(state,value){
            state.playList.push(value)
        },
    },
    actions: {
        async getLyric({ commit }, value) {
            const res = await getMusicLyric(value)
            commit("updataLyricList", res.data.lrc.lyric)
        }
    },
    module: {}
})